<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>资源管理 Arvato企业微信管理后台</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../static/css/font.css">
		<link rel="stylesheet" href="../../static/css/weadmin.css">
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
	      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
	    <![endif]-->
	</head>

	<body>
		<div class="weadmin-body">
			<form id="resource_form" action="" method="post" class="layui-form layui-form-pane">
				<div class="layui-form-item">
					<label for="parent_name" class="layui-form-label">
                        <span class="we-red">*</span>父级名称
                    </label>
					<div class="layui-input-inline">
						<input type="text" id="parent_name" readonly name="parentName" required="" lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="resource_name" class="layui-form-label">
                        <span class="we-red">*</span>资源名称
                    </label>
					<div class="layui-input-inline">
						<input type="text" id="resource_name" name="resourceName" required="" lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="resource_url" class="layui-form-label">
                        资源URL
                    </label>
					<div class="layui-input-inline">
						<input type="text" id="resource_url" name="resourceUrl" required="" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="icon" class="layui-form-label">
                        菜单图标
                    </label>
					<div class="layui-input-inline">
						<input type="text" id="icon" name="icon" required="" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="sortCode" class="layui-form-label">
                        排序码
                    </label>
					<div class="layui-input-inline">
						<input type="text" id="sortCode" name="sortCode" required="" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label for="resource_type" class="layui-form-label">
                        <span class="we-red">*</span>资源类别
                    </label>
					<div class="layui-input-inline">
						<select id="resource_type" name="type" class="valid">
							<option value="0">菜单项</option>
							<option value="1">API接口</option>
							<option value="2">免检URL</option>
						</select>
					</div>
				</div>
				<!-- <div class="layui-form-item">
					<label for="name" class="layui-form-label">
                        <span class="we-red">*</span>资源状态
                    </label>
					<div class="layui-input-inline">
						<select id="resource_status" name="status" class="valid">
							<option value="1">正常</option>
							<option value="0">禁止</option>
						</select>
					</div>
				</div> -->
				<div class="layui-form-item layui-form-text">
					<label for="resource_note" class="layui-form-label">
                        描述
                    </label>
					<div class="layui-input-block">
						<textarea placeholder="请输入内容" id="resource_note" name="note" class="layui-textarea"></textarea>
					</div>
				</div>
				<div class="layui-form-item">
					<button class="layui-btn" lay-submit="" lay-filter="add">提交</button>
				</div>
			</form>
		</div>
		<script src="../../lib/layui/layui.js" charset="utf-8"></script>
		<script src="../../static/js/admin.js" charset="utf-8"></script>
		<script src="../../publicjs/jquery-1.8.0.min.js" charset="utf-8"></script>
		<script src="../../publicjs/smallkingutil.js" charset="utf-8"></script>
		<script type="text/javascript">
			layui.extend({
				admin: '{/}../../static/js/admin'
			});
			layui.use(['form', 'layer', 'admin'], function() {
				var form = layui.form,
					admin = layui.admin,
					layer = layui.layer;
				var parentName = commonUtil.getRequestParam("parentName");
				var parentId = commonUtil.getRequestParam("parentId");
				$("#parent_name").val(parentName);
				// 首先看看当前是新增操作还是更新操作
				var resourceId = commonUtil.getRequestParam("resourceId");
				if(resourceId) {
					// 请求后台得到当前修改的用户数据，将其显示在表单里
					var ajaxParam = {
						url: commonUtil.domain() + '/admin/right/resource/detail',
						data: {
							resourceId: resourceId
						}
					}
					ajaxUtil.post(ajaxParam, function(data) {
						parentId = data.data.parentId;
						formUtil.setForm($('#resource_form'), data.data);
						form.render("select");
					});
				}
				// 监听表单提交
				form.on('submit(add)', function(data) {
					console.info(resourceId);
					var data = data.field;
					data.parentId = parentId;
					var url, msg;
					// 有resourceId就是修改，没有resourceId就是新增
					if(resourceId) {
						url = commonUtil.domain() + "/admin/right/resource/update";
						msg = "修改";
						data.resourceId = resourceId;
					} else {
						url = commonUtil.domain() + "/admin/right/resource/insert";
						msg = "新增";
					}
					console.log(data);
					var ajaxParam = {
						url: url,
						data: data
					}
					// 发送ajax请求 提交当前表单
					ajaxUtil.post(ajaxParam, function(data) {
						console.info(data);
						if(data.code == 200) {
							layer.alert(msg + "成功", {
								icon: 6
							}, function() {
								// 刷新表格
								var parentHtml = window.parent;
								parentHtml.resourceTable.refresh();
								parentHtml.initTree();
								// 获得frame索引
								var index = parent.layer.getFrameIndex(window.name);
								// 关闭当前frame
								parent.layer.close(index);
							});
						} else {
							layer.alert(msg + "失败" + JSON.stringify(data));
						}
					});
					return false;
				});
			});
		</script>
		<script>
			$(function() {
				commonUtil.setMaxLength(40);
			})
		</script>
	</body>

</html>